package com.example.helloapi;

import java.io.IOException;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import io.grpc.ServerBuilder;
import io.grpc.Server;

@SpringBootApplication
public class HelloApiApplication {

    public static void main(String[] args) {
        SpringApplication.run(HelloApiApplication.class, args);

        // 创建并启动 gRPC 服务器
        int port = 50051;  // 可以修改为你需要的端口
        Server server = ServerBuilder.forPort(port)
                .addService(new GreeterImpl())  // 注册服务实现类
                .build();

        System.out.println("Server started, listening on " + port);
        try {
            server.start();
            // 持续运行直到服务被停止
            server.awaitTermination();
        } catch (IOException e) {
            e.printStackTrace();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        
    }
}

